package com.bysj.lms.service.impl;

import com.bysj.lms.pojo.entity.CourseOutline;
import com.bysj.lms.mapper.CourseOutlineMapper;
import com.bysj.lms.service.ICourseOutlineService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bysj.lms.utils.EasyExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xiaojiakai
 * @since 2022-02-04
 */
@Service
public class CourseOutlineServiceImpl extends ServiceImpl<CourseOutlineMapper, CourseOutline> implements ICourseOutlineService {
    
    @Autowired
    CourseOutlineMapper courseOutlineMapper;
    
    @Override
    public boolean adds(MultipartFile excel,String versionNumber) throws IOException {
        List<CourseOutline> read = EasyExcelUtil.read(excel, CourseOutline.class,2);
        read.forEach(courseOutline -> System.out.println(courseOutline));
        read.forEach(courseOutline -> {
            courseOutline.setVersionNumber(versionNumber);
        });
        int adds = courseOutlineMapper.adds(read);
        return adds>0?true:false;
    }
    
    @Override
    public List<CourseOutline> list(String versionNumber) {
        List<CourseOutline> list = lambdaQuery().eq(CourseOutline::getVersionNumber,versionNumber).isNotNull(CourseOutline::getShangji).list();
        return list;
    }

    @Override
    public List<CourseOutline> listByClass(Integer classId) {

        return null;
    }
}
